package com.example.foobar.dao.service.impl;

import com.example.foobar.entity.DidiCompany;
import com.example.foobar.mapper.DidiCompanyMapper;
import com.example.foobar.dao.service.DidiCompanyDaoService;
import com.example.foobar.param.DidiCompanyPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 公司 服务实现类
 *
 * @author 郑英奔
 * @since 2021-11-16
 */
@Slf4j
@Service
public class DidiCompanyDaoServiceImpl extends BaseServiceImpl<DidiCompanyMapper, DidiCompany> implements DidiCompanyDaoService {

    @Autowired
    private DidiCompanyMapper didiCompanyMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDidiCompany(DidiCompany didiCompany) throws Exception {
        return super.save(didiCompany);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDidiCompany(DidiCompany didiCompany) throws Exception {
        return super.updateById(didiCompany);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDidiCompany(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<DidiCompany> getDidiCompanyPageList(DidiCompanyPageParam didiCompanyPageParam) throws Exception {
        Page<DidiCompany> page = new PageInfo<>(didiCompanyPageParam, OrderItem.desc(getLambdaColumn(DidiCompany::getCreateTime)));
        LambdaQueryWrapper<DidiCompany> wrapper = new LambdaQueryWrapper<>();
        IPage<DidiCompany> iPage = didiCompanyMapper.selectPage(page, wrapper);
        return new Paging<DidiCompany>(iPage);
    }

}
